package org.example.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.example.common.Result;
import org.example.pojo.entity.TbUser;
import org.example.pojo.entity.User;
import org.example.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api("用户登录模块")
@RestController
public class LoginController {

    @Autowired
    private TbUserService userService;

    @PostMapping("registerUser")
    @ApiOperation("注册业务")
    public Result registerUser(@RequestBody @ApiParam("用户信息") User user){
        userService.registerUser(user);
        return Result.OK("success");
    }

    @PostMapping("login")
    @ApiOperation("登录业务")
    public Result login(@RequestBody @ApiParam("用户信息") User user){
        TbUser tbUser = userService.login(user);
        return Result.OK(JSON.toJSONString(tbUser));
    }
}
